<template>
    <div class="mod-prod-prodTag">
        <search-form :showArea="true" :showStatus="false" @search="customSearch"></search-form>
        <avue-crud ref="crud" :page="page" :data="dataList" :table-loading="dataListLoading" :option="tableOption" :search="query"
                   @search-change="searchChange" @on-load="" @refresh-change="">
            <template slot-scope="scope" slot="menu">
                <el-button type="primary" size="small" icon="el-icon-edit"
                           @click="handleAudit(scope.row)">详情</el-button>
                <el-button type="warning" size="small" icon="el-icon-edit"
                           @click="toAudit(scope.row)">审核</el-button>
                <el-button type="danger" size="small" icon="el-icon-error"
                           @click="returnReview(scope.row)">驳回</el-button>
            </template>

        </avue-crud>
        <el-dialog title="数据填报详情" :close-on-click-modal="false" :visible.sync="editVisible" width="95%" height="90vh" top="5vh" custom-class="my-dialog">
            <target-edit ref="editRef" :editFormData="editFormData" controlType="province" @success="success"></target-edit>
        </el-dialog>
    </div>
</template>

<script>
import {
	tableOption
} from '@/crud/audit/audit'
import TargetEdit from '@/template/target-edit/index.vue'
import SearchForm from '@/components/search-form/index.vue'
export default {
	data() {
		return {
            params: {
                evalYear: wfy.format('yyyy', new Date()),
                evalStatus: "Y"
            },
            editFormData: {},
            editVisible: false,
			dataList: [],
			page: {
				total: 0, // 总页数
				currentPage: 1, // 当前页数
				pageSize: 10 // 每页显示多少条
			},
            query: {
                evalYear: wfy.format('yyyy', new Date())
            },
			dataListLoading: false,
			tableOption: tableOption,
			permission: {
				delBtn: this.isAuth('prod:prodTag:delete')
			},
			addOrUpdateVisible: false
		}
	},
	components: {
        SearchForm,
        TargetEdit

    },
	created() {},
  activated () {
    console.info("进入省级ACTIVI")
    if(!wfy.empty(wfy.getPara("evalYear"))){
      console.info("进入升级审核刷新")
      this.getDataList(1,{
        //reginId: wfy.getPara("reginId"),
        evalYear: wfy.getPara("evalYear"),
        evalStatus: "Y",
      })
    }else{
        this.getDataList(1,this.params);
    }
  },
	mounted() {
        this.init();
    },
	methods: {
        init(){
            this.yearsList = [];
            for (let i = 2024; i < 2060; i++) {
                this.yearsList.push({
                    value : i,
                    label : i
                })
            }
            let areaList = this.$store.state.user.area.area;
            this.tableOption.column.forEach((item) => {
                if(item.prop === 'evalYear'){
                    item.dicData = this.yearsList
                }
                if(item.prop === "reginId"){
                    areaList.forEach((area) => {
                        item.dicData.push({
                            value : area.code,
                            label : area.name
                        })
                    })
                    console.log('🚀 ~ item.dicData', item.dicData)
                }
            })
             // this.getDataList(1,{
             //     evalYear: wfy.format('yyyy', new Date()),
             //     evalStatus: "Y"
             // })
        },
        customSearch(params){
            this.getDataList(1,{
                evalYear: params.evalYear,
                evalStatus: "Y",
                reginId: params.regionId,
                provinceId: params.provinceId,
                cityId: params.cityId
            })
        },
        getDataList(page, params, done) {
            this.dataListLoading = true
            this.dataList = []
            this.params = params;
            this.$http({
                url: this.$http.adornUrl('/eval/getEvalInfoList'),
                method: 'post',
                data: this.$http.adornData(
                    Object.assign(
                        {
                            current: page == null ? this.page.currentPage : page.currentPage,
                            size: page == null ? this.page.pageSize : page.pageSize,
                            evalStatus: "Y",
                        },
                        params
                    )
                )
            }).then(({
                data
            }) => {
                console.log('🚀 ~ data', data)
                this.dataList = data;
                // this.totalResult.forEach((item) => {
                //     this.dataList.push(item.evaluationMain)
                // })
                this.page.total = data.length
                this.dataListLoading = false
                if (done) {
                    done()
                }
            })
        },
        toAudit(row){
            console.log('🚀 ~ row', row)
            this.$confirm('审核后不可撤销，是否继续？', '友情提醒', {}).then(() => {
                let params = {
                    'evalMainId': row.evalMainId,
                    'reginEvalDesc': row.reginEvalDesc,
                    'confirmDesc': row.confirmDesc,
                    'expertLack': row.expertLack,
                    'expertBiz': row.expertBiz,
                    'evalStatus': "P",
                    "createBy": this.$store.state.user.name,
                    "createTime": wfy.format('yyyy-MM-dd HH:mm:ss',new Date()),
                    "lstUpdBy": this.$store.state.user.name,
                    "lstUpdTime": wfy.format('yyyy-MM-dd HH:mm:ss',new Date()),
                    "auditBy": this.$store.state.user.name,
                    "auditDate": wfy.format('yyyy-MM-dd HH:mm:ss',new Date())
                }
                this.$http({
                    url: this.$http.adornUrl('/eval/updMainSelCol'),
                    method: 'post',
                    data: this.$http.adornData(params)
                }).then(({
                    data
                }) => {
                    if (data) {
                        this.getDataList(1,{
                            evalStatus: "Y"
                        })
                    }
                })
            })
        },
		// 新增 / 修改
		handleAudit(row) {
            console.log('🚀 ~ row', row)
            this.$http({
                url: this.$http.adornUrl('/eval/getNowEvalInfo'),
                method: "post",
                data: this.$http.adornData({
                    "evalMainId": row.evalMainId,
                    "evalYear": row.evalYear,
                    "reginId": row.reginId
                })
            }).then(({
                data
            }) => {
                console.log('🚀 ~ data', data)
                let orReadyItem = {
                    affixList: data[0].affixList,
                    anIndexEvaluationMain: data[0].evaluationMain,
                    currentEvalDtl: data[0].currentEvalDtl,
                    currentIndexInfo: data[0].currentIndexInfo,
                    scoreList: data[0].scoreList
                }
                this.initSuccess(orReadyItem);
            })
		},
        /**
         * 刷新回调
         */
        initSuccess(data) {
            console.log('🚀 ~ data', data)
            // sessionStorage.cityInitFormData = JSON.stringify(wfy.deepCopy(data));
            // this.$router.push({
            //     path: 'auditp-detail',
            //     query: { id : data.anIndexEvaluationMain.evalMainId }
            // })

            this.editFormData = data;
            this.$nextTick(() => {
                this.editVisible = true;
                this.$refs.editRef.initData();
            })
        },
        // 驳回
        returnReview(row){
            this.$prompt("请输入驳回原因","友情提醒",{}).then((res) => {
                console.log('🚀 ~ res', res)
                this.$http({
                    url: this.$http.adornUrl('/eval/updMainSelCol'),
                    method: "post",
                    data: this.$http.adornData({
                        "evalMainId": row.evalMainId,
                        "evalStatus": "N",
                        "confirmDesc" : res.value
                    })
                }).then(({
                    data
                }) => {
                    this.$message.success("已驳回");
                })
            })
        },
		/**
		 * 刷新回调
		 */
		refreshChange() {
			this.getDataList(this.page)
		},
		searchChange(params, done) {
            if(wfy.empty(params)){
                this.$message.warning("查询条件不能为空");
                done()
                return;
            }
           /*** if(wfy.empty(params.reginId)){
                this.$message.warning("请选择区县后进行查询");
                done()
                return;
            }
            if(wfy.empty(params.evalYear)){
                this.$message.warning("填报年度不能为空");
                done()
                return;
            }**/
			this.getDataList(this.page, params, done)
		},
        success(message){
            console.info("-------message----")
            console.info(message)
            this.editVisible = false;
            this.$alert("审批成功！","友情提醒",{
                callback: () => {
                    // this.removeTabHandle(this.mainTabsActiveName)
                    // this.$router.push({
                    //     path: 'auditp-review',
                    //     query: { reginId : message.reginId, evalYear : message.evalYear, evalStatus : 'Y' }
                    // })
                    this.getDataList(1,{
                        evalYear: message.evalYear,
                        evalStatus: "Y",
                    })
                }
            })
        }
	}
}
</script>

<style scoped>

.mod-prod-prodTag >>> .my-dialog{
    height: 90vh !important;
    overflow-y: scroll;
}

</style>
